package djl;

import static org.junit.Assert.assertTrue;
import djl.test.RobotTestBed;
import robocode.control.events.BattleCompletedEvent;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IRobotSnapshot;

/**
 * Illustrates JUnit testing of Robocode robots. This test verifies if DaBeast drives passes along
 * the left wall.
 * 
 * @author David Joel Lazaro
 * 
 */
public class TestDaBeastLeftWall extends RobotTestBed {
  boolean bottomLeftCorner = false;
  boolean topLeftCorner = false;

  /**
   * Specifies that Corners and DaBeast are to be matched up in this test case.
   * 
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.Crazy,djl.DaBeast";
  }

  /**
   * This test runs for 10 rounds.
   * 
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {
    return 10;
  }

  /**
   * Checks to see if DaBeast to the bottom and top left corners.
   * 
   * @param event Details about the completed turn.
   */
  @Override
  public void onTurnEnded(TurnEndedEvent event) {
    IRobotSnapshot robot = event.getTurnSnapshot().getRobots()[1];
    double xCoordinate = robot.getX();
    double yCoordinate = robot.getY();
    int getHeight = battleFieldSpec.getHeight();

    if (xCoordinate < 25 && yCoordinate < 25) {
      bottomLeftCorner = true;
    }
    if (xCoordinate < 25 && yCoordinate >= (getHeight - 25)) {
      topLeftCorner = true;
    }
  }

  /**
   * The actual test, which asserts that DaBeast passed by the left wall.
   * 
   * @param event Details about the completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    assertTrue("Check Corner", bottomLeftCorner);
    assertTrue("Check Corner", topLeftCorner);
  }
}
